package com.ha.controller.admin;

import com.ha.dto.GarbageDTO;
import com.ha.dto.GarbagePageDTO;
import com.ha.entity.Garbage;
import com.ha.result.PageResult;
import com.ha.result.Result;
import com.ha.service.GarbageService;
import com.ha.vo.GarbageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: GarbageController
 * Package: com.ha.controller.admin
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/4/21  14:01
 * @Version 1.0
 */
@RestController("adminGarbageController")
@Api(tags = "垃圾管理接口")
@Slf4j
@RequestMapping("/admin/garbage")
public class GarbageController {

    @Autowired
    private GarbageService garbageService;


    /**
     * 垃圾分也查询
     * @param garbagePageDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("垃圾分页查询")
    public Result<PageResult> page( GarbagePageDTO garbagePageDTO){
        log.info("垃圾分页查询参数为 ：{}",garbagePageDTO);
        PageResult pageResult = garbageService.pageQuery(garbagePageDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改垃圾回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id回显数据")
    public Result<GarbageVO> getById(@PathVariable Long id ){
        GarbageVO garbageVO = garbageService.getById(id);
        return Result.success(garbageVO);
    }

    /**
     * 更新垃圾数据
     * @param garbageDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新垃圾操作")
    public Result update(@RequestBody GarbageDTO garbageDTO){
        garbageService.update(garbageDTO);
        return Result.success();
    }

    /**
     * 根据id删除垃圾
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除垃圾")
    public  Result delete(@PathVariable Long id ){
        garbageService.deleteById(id);
        return Result.success();
    }

    /**
     * 新增垃圾操作
     * @param garbageDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增垃圾")
    public Result addGarbage(@RequestBody GarbageDTO garbageDTO){
        garbageService.addGarbage(garbageDTO);
        return Result.success();
    }
}
